export default {
    data(){
        return {

        }
    },
    methods:{
        getNowDate(){
            var d = new Date();
            var year = d.getFullYear();
            var month = d.getMonth() + 1;
            var day = d.getDate();
            var dateStr = year + '-' + this.getFormatDate(month) + '-' + this.getFormatDate(day);
            return dateStr;
        },
        getFormatDate(value){
            var result;
            result = value < 10 ? ("0" + value) : value;
            return result;
        },
        getDifferScale(value){
            var format;
            //获取转化比（天数跟毫秒数的比例）
            if (value == 1) {
                format = parseFloat(24 * 60 * 60 * 1000);
            }
                //获取转化比（小时数跟毫秒数的比例）
            else if (value == 2) {
                format = parseFloat(60 * 60 * 1000);
            }
                //获取转化比（分钟数跟毫秒数的比例）
            else if (value == 3) {
                format = parseFloat(60 * 1000);
            }
                //获取转化比（秒数跟毫秒数的比例）
            else if (value == 4) {
                format = parseFloat(1000);
            }
            return format;

        },
        getDifferDate(firstDate, secondDate, differ){
            //1)将两个日期字符串转化为日期对象
            var startDate = new Date(firstDate);
            var endDate = new Date(secondDate);
            //2)计算两个日期相差的毫秒数
            var msecNum = endDate.getTime() - startDate.getTime();
            //3)计算两个日期相差的天数
            var dayNum = Math.floor(msecNum /this.getDifferScale(differ));
            return dayNum;
        },
        // 获取时间指定天数
        getDay(day) {
            var today = new Date();
            var targetday_milliseconds =
                today.getTime() + 1000 * 60 * 60 * 24 * day;
            today.setTime(targetday_milliseconds); //注意，这行是关键代码
            var tYear = today.getFullYear();
            var tMonth = today.getMonth();
            var tDate = today.getDate();
            tMonth = this.doHandleMonth(tMonth + 1);
            tDate = this.doHandleMonth(tDate);
            return tYear + "-" + tMonth + "-" + tDate ;
        },
        doHandleMonth(month) {
            var m = month;
            if (month.toString().length == 1) {
                m = "0" + month;
            }
            return m;
        },
    }
}